package com.jdk.learn.exam.gui;

import javax.swing.*;
import java.awt.*;

/**
 * Created by ricky
 * on 2018/2/27.
 * GUI工具类
 */
public class GUIUtils {

    /**
     * 获取默认窗体
     * 长300，宽300
     * 偏移500,500
     *
     * @param title
     *
     * @return
     */
    public static JFrame getDefaultFrame(String title) {
        JFrame frame = new JFrame(title);
        frame.setBounds(500, 300, 300, 300);//设置偏移以及宽高
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭
        frame.setVisible(true);//设置可见
        return frame;
    }

    /**
     * 获取默认带边框的Border
     *
     * @param title
     *
     * @return
     */
    public static javax.swing.border.Border getDefaultTitleBorder(String title) {
        javax.swing.border.Border border = BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder()
                , title);
        return border;
    }
    /**
     * 边框
     *
     * @param color
     *
     * @return
     */
    public static javax.swing.border.Border getDefaultLineBorder(Color color) {
        javax.swing.border.Border border = BorderFactory.createLineBorder(color);
        return border;
    }

    /**
     * 获取布局的JPanel
     *
     * @param layout
     *
     * @return
     */
    public static JPanel getDefaultJPanel(LayoutManager layout) {
        JPanel panel = new JPanel();
        if (layout != null) {
            panel.setLayout(layout);
        }
        return panel;
    }


    public static void Sleep() {
        try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
